<template>
	<view class="wrap">
		<!-- 订单状态 -->
		<view class="status-box">
			<view class="status">订单{{orderInfo.status}}</view>
			<view class="desc">感谢您对我们的信任，欢迎再次光临</view>
			<view class="action-btns">
				<view class="action-btn" v-if="orderInfo.status=='已完成'" @tap="oneMore">
					<u-icon name="reload" color="#EE2F37" size="40"></u-icon>
					<text style="color: #EE2F37;">再来一单</text>
				</view>
				<view class="action-btn" @tap="contactShop">
					<u-icon name="phone" color="#666" size="40"></u-icon>
					<text>联系商家</text>
				</view>
			</view>
		</view>

		<!-- 堂食时显示桌号 -->
		<view class="table-info" v-if="selCurrent == 0">
			<view class="table-num">
				<text class="num">{{orderInfo.seatNums}}</text>
				<text class="label">桌号</text>
			</view>
		</view>

		<!-- 商品列表 -->
		<view class="goods-list">
			<view class="title">商品信息</view>
			<view class="goods-item" v-for="(item, index) in orderInfo.orderDetails" :key="index">
				<image class="goods-img" :src="item.image" mode="aspectFill"></image>
				<view class="goods-info">
					<view class="name">{{item.name}}</view>
					<view class="price">
						<text>¥{{item.amount}}</text>
						<text class="num" v-if="item.name!='配送费'||item.name!='打包费'">x{{item.number}}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 价格信息 -->
		<view class="price-info">
			<view class="price-item">
				<text>商品总价</text>
				<text>¥{{orderInfo.totalAmount}}</text>
			</view>
			<view class="price-item" v-for="(item,index) in orderInfo.orderDetailOthers" :key="index">
				<view class="item-left">
					<text>{{item.name}}</text>
				</view>
				<view class="item-right">
					<text class="amount">¥{{item.amount}}</text>
					<text class="number">x{{item.number}}</text>
				</view>
			</view>
			<view class="price-total">
				<text>实付款</text>
				<text class="amount">¥{{orderInfo.amount}}</text>
			</view>
		</view>

		<!-- 订单信息 -->
		<view class="order-info">
			<view class="title">订单信息</view>
			<view class="price-item" v-if="selCurrent != 0">
				<view class="item-left">
					<text>收货信息</text>
				</view>
				<view class="item-right">
					<text class="amount">{{orderInfo.address}}</text>
					<text class="number">{{orderInfo.phone}}</text>
					<text class="number">{{orderInfo.consignee}}</text>
				</view>
			</view>
			<view class="info-item">
				<text>订单编号</text>
				<text>{{orderInfo.id}}</text>
			</view>
			<view class="info-item">
				<text>下单时间</text>
				<text>{{orderInfo.orderTime}}</text>
			</view>
			<view class="info-item">
				<text>支付方式</text>
				<text>{{orderInfo.payMethod}}</text>
			</view>
			<view class="info-item" v-if="orderInfo.remark">
				<text>备注</text>
				<text>{{orderInfo.remark}}</text>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';
	import {
		getOrderDetail,
		againOrder
	} from "@/request/API.js";
	export default {
		data() {
			return {
				orderInfo: {}, // 订单详情
			}
		},
		onLoad() {
			this.getData()
			console.log(this.orderInfo);
		},
		methods: {
			async getData() {
				const {
					data
				} = await getOrderDetail(this.orderInfoId);
				this.orderInfo = data;
			},
			// 再来一单
			async oneMore() {
				await againOrder(this.orderInfo.id)
				this.$store.commit('setSubCurrent', this.orderInfo.seatStatus);
				uni.navigateTo({
					url: "/subPack/index/indexSettlement"
				})
			},
			// 联系商家
			contactShop() {
				// 拨打商家电话
				uni.makePhoneCall({
					phoneNumber: this.shopDetail.phone
				});
			}
		},
		computed: {
			...mapState(['selCurrent', 'orderInfoId'])
		},
	}
</script>
<style lang="scss">
	.wrap {
		background: #f5f5f5;
		min-height: 100vh;
		padding-bottom: 30rpx;

		.status-box {
			background: #fff;
			padding: 40rpx 30rpx;
			margin-bottom: 20rpx;

			.status {
				font-size: 36rpx;
				font-weight: bold;
				margin-bottom: 16rpx;
			}

			.desc {
				font-size: 26rpx;
				color: #666;
				margin-bottom: 30rpx;
			}

			.action-btns {
				display: flex;
				justify-content: space-around;
				gap: 40rpx;

				.action-btn {
					display: flex;
					flex-direction: column;
					align-items: center;

					text {
						font-size: 24rpx;
						color: #666;
						margin-top: 8rpx;
					}
				}
			}
		}

		.table-info,
		.delivery-info {
			background: #fff;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.label {
				font-size: 28rpx;
				color: #666;
				margin-bottom: 16rpx;
			}

			.content {
				.detail {
					font-size: 30rpx;
					font-weight: bold;
					margin-bottom: 12rpx;
				}

				.user {
					font-size: 26rpx;
					color: #666;

					text {
						margin-right: 20rpx;
					}
				}
			}

			.delivery-time {
				margin-top: 20rpx;

				.time {
					font-size: 30rpx;
					font-weight: bold;
				}
			}
		}

		.goods-list,
		.order-info,
		.price-info {
			background: #fff;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.title {
				font-size: 32rpx;
				font-weight: bold;
				margin-bottom: 30rpx;
			}

			.goods-item {
				display: flex;
				margin-bottom: 30rpx;

				.goods-img {
					width: 120rpx;
					height: 120rpx;
					border-radius: 12rpx;
					margin-right: 20rpx;
				}

				.goods-info {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-size: 28rpx;
					}

					.price {
						display: flex;
						justify-content: space-between;
						font-size: 28rpx;
						color: #333;

						.num {
							color: #999;
						}
					}
				}
			}

			.info-item {
				display: flex;
				justify-content: space-between;
				margin-bottom: 20rpx;
				font-size: 28rpx;
				color: #666;
			}

			.price-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;
				font-size: 28rpx;
				color: #666;

				.item-left {
					flex: 1;
					line-height: 1.5;
					display: flex;
					align-items: center;
				}

				.item-right {
					text-align: right;

					.amount {
						display: block;
						margin-bottom: 8rpx;
					}

					.number {
						display: block;
						font-size: 24rpx;
						color: #999;
					}
				}
			}

			.price-total {
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
				padding-top: 20rpx;
				border-top: 1px solid #f5f5f5;
				font-size: 30rpx;
				font-weight: bold;

				.amount {
					color: #EE2F37;
				}
			}
		}

		.table-info {
			background: #fff;
			padding: 30rpx;
			margin-bottom: 20rpx;
			height: 180rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			.table-num {
				display: flex;
				flex-direction: column;
				align-items: center;
				position: relative;

				text {
					&.num {
						font-size: 80rpx;
						font-weight: bold;
						color: #EE2F37;
						line-height: 1;
					}

					&.label {
						font-size: 24rpx;
						color: #999;
						margin-top: 16rpx;
					}
				}
			}
		}
	}
</style>